package com.mzpai.product.service.impl;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gexin.fastjson.JSONObject;
import com.mzpai.product.mapper.StoreOrderCartInfoMapper;
import com.mzpai.product.model.StoreOrderCartInfo;
import com.mzpai.product.service.StoreOrderCartInfoService;
import com.mzpai.service.impl.BaseServiceImpl;
/**
 *
 * <b>商品属性信息 | Service</b><br>
 *
 * yanglijun 2021-04-10 09:16:49
 * 
 *  @version 1.0.0
 *
 */
@Service
public class StoreOrderCartInfoServiceImpl extends BaseServiceImpl<StoreOrderCartInfo> implements StoreOrderCartInfoService {

	Logger logger = LoggerFactory.getLogger(StoreOrderCartInfo.class);

	@Autowired 
	private StoreOrderCartInfoMapper mapper;

	/**
	 * 根据订单id，查询订单商品信息
	 */
	@Override
	public List<StoreOrderCartInfo> getListByOrderId(Integer oid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("oid", oid);
		List<StoreOrderCartInfo> list = mapper.getList(map);
		for(StoreOrderCartInfo o : list) {
			String str = o.getCartInfo();
			//获取数量
			JSONObject userJson = JSONObject.parseObject(str);
			o.setCartNum(Integer.parseInt(userJson.get("cart_num")+""));
			//获取商品名称
			userJson = JSONObject.parseObject(userJson.get("productInfo") + "");
			o.setProductName(userJson.get("store_name") + "");
			//获取规格
			userJson = JSONObject.parseObject(userJson.get("attrInfo") + "");
			o.setImage(userJson.get("image") + "");
			o.setAttrValueName(userJson.get("suk") + "");
			o.setPrice(new BigDecimal(userJson.get("price") + ""));
			o.setCartInfo("");
		}
		return list;
	}

	@Override
	public void insertBatch(List<StoreOrderCartInfo> storeOrderCartInfoList) {
		mapper.insertBatch(storeOrderCartInfoList);
	}
}